package com.taotao.job.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 触发状态
 *
 * @author fanbeibei
 * @version 1.0
 * @date 2021/2/3 16:50
 */
@Getter
@AllArgsConstructor
public enum TriggerStatus {
    /**
     * 还未收到执行器触发的回应
     */
    TRIGGERING(0, "触发中"),
    /**
     *
     */
    SUCCESS(1,"触发成功"),
    /**
     *
     */
    FAIL(2,"触发失败"),
    /**
     *
     */
    MISFIRE(3,"错过触发"),
    ;
    private Integer code;

    private String text;
    

    private static final Map<Integer, TriggerStatus> codeTextMap = new HashMap<>();

    static {
        TriggerStatus[] values = TriggerStatus.values();
        for (TriggerStatus val : values) {
            codeTextMap.put(val.code, val);
        }
    }


    public static TriggerStatus getByCode(Integer code) {
        return codeTextMap.get(code);
    }

    public static String getTextByCode(Integer code) {
        TriggerStatus v = getByCode(code);

        if (null == v) {
            return "未知Code:" + code;
        }
        return v.text;
    }
}
